package com.tsinghuabigdata.edu.ddmath.util;

import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * <p>
 * Created by yanshen@tsinghuabigdata.com on 2016/1/5.
 * </p>
 *
 * @author yanshen@tsinghuabigdata.com
 * @version V1.0
 * @packageName: com.tsinghuabigdata.edu.ddmath.util
 * @createTime: 2016/1/5 17:17
 */
public class AssertUtils {
    /**
     * 在Asserts中获取图标
     * @param resources
     * @param imagePath
     * @return
     */
    public static Bitmap getImageFromAssetsFile(Resources resources, String imagePath) {
        Bitmap image = null;
        AssetManager am = resources.getAssets();
        try {
            InputStream is = am.open(imagePath);
            image = BitmapFactory.decodeStream(is);
            is.close();
        } catch (IOException e) {
            AppLog.i("in asserts not found " + imagePath, e);
        }
        return image;
    }

    /**
     * 得到netconfig.properties配置文件中的所有配置属性
     *
     * @return Properties对象
     */
    public static Properties getNetConfigProperties() {
        Properties props = new Properties();
        InputStream in = AppUtils.class.getResourceAsStream("/assets/netconfig.properties");

        try {
            props.load(in);
        } catch (IOException e) {
            AppLog.i("读取服务器地址配置", e);
        }
        return props;
    }
}
